﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enter.Services.DataCache;
using Enter.Services.Mail;
using Enter.Mvc.Base.Controllers;
using System.Web.Mvc;
using Enter.Entity;
using Enter.Mvc.Mall.Model;
using Newtonsoft.Json;

namespace Enter.Mvc.Mall.Controllers
{
   public class AreaController: BaseControllers
    {
        private readonly ICache icache;
        private readonly IMail imail;

        public AreaController(ICache cache, IMail mail)
        {
            this.icache = cache;
            this.imail = mail;
        }
        public ActionResult getArea()
        {
            List<AreaModel> all = getArealist("0");
            object obj = new { area = all };
            string result = JavaScriptConvert.SerializeObject(obj);
            return Content(result);
          
        }
        private List<AreaModel> getArealist(string ParentNo)
        {
            List<T9002_AreaEntity> all = imail.GetArea();
            List<T9002_AreaEntity> one = all.FindAll(a => a.ParentNo == ParentNo);
            List<AreaModel> area = new List<AreaModel>();
            foreach (T9002_AreaEntity entity in one)
            {
                AreaModel model = new AreaModel();
                model.AreaNO = entity.AreaNO;
                model.AreaName = entity.AreaName;
                model.ChildList = getArealist(model.AreaNO);
                area.Add(model);
            }
            return area;
        }
        
    }
}
